package com.demostic.demostic_test.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.PayloadCallback;
import com.accloud.cloudservice.VoidCallback;
import com.accloud.service.ACDeviceDataMgr;
import com.accloud.service.ACDeviceMsg;
import com.accloud.service.ACException;
import com.accloud.utils.LogUtil;
import com.bumptech.glide.Glide;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.base.BaseActivity;
import com.demostic.demostic_test.entity.PropertyInfo;
import com.demostic.demostic_test.ui.PopupWindowWithMask;
import com.demostic.demostic_test.utils.Constants;
import com.demostic.demostic_test.utils.DeviceUtils;
import com.demostic.demostic_test.utils.DisplayUtil;
import com.demostic.demostic_test.utils.MyLog;
import com.demostic.demostic_test.utils.SpUtils;
import com.demostic.demostic_test.utils.TimeUtil;
import com.demostic.demostic_test.utils.ToastUtils;
import com.google.gson.Gson;

import org.java_websocket.drafts.Draft_75;

public class MapActivity_786 extends BaseActivity implements View.OnClickListener {
    public static final String INTENT_ACTION = "com.example.MapActivity";
    private final String TAG = MapActivity_786.class.getSimpleName();
    private View anchorView;
    private int batteryCap;
    private Context context;
    private long deviceId;
    private IntentFilter filter;
    private ImageView image_back;
    private ImageView image_battery;
    private ImageView image_clock;
    private ImageView image_control;
    private ImageView image_gif;
    private ImageView image_keyPoint;
    private ImageView image_recharge;
    private ImageView image_setting;
    private ImageView image_start;
    private Intent intent_clock;
    private boolean isAlongWall;
    private boolean isCharging;
    private boolean isClickTab;
    private boolean isError;
    private boolean isKeyPoint;
    private boolean isMaxMode;
    private boolean isRandom;
    private boolean isRecharge;
    private boolean isRemote;
    private boolean isStandBy;
    private boolean isStart;
    private boolean isStoped;
    private LinearLayout line_state;
    private ACDeviceMsg msg_workMode;
    private ACDeviceDataMgr.PropertyReceiver myPropertyReceiver;
    private String physicalDeviceId;
    private PopupWindow popWnd_control;
    private PopupWindow popWnd_error;
    private MyReceiver receiver;
    private boolean registerTag;
    private RelativeLayout relativeLayout;
    private String subdomain;
    private RelativeLayout tab_keyPoint;
    private RelativeLayout tab_recharge;
    private RelativeLayout tab_start;
    private TextView tv_area;
    private TextView tv_keyPoint;
    private TextView tv_recharge;
    private TextView tv_start;
    private TextView tv_state;
    private TextView tv_time;

    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        getDeviceInfo();
        initView();
        initReceiver();
        setListener();
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        this.isStoped = false;
        initPropertyReceiver();
        getClockInfo();
        getWorkStatus();
        registerPropertyReceiver();
        if (!this.registerTag) {
            this.registerTag = true;
            registerReceiver(this.receiver, this.filter);
        }
    }

    public void initPropertyReceiver() {
        this.myPropertyReceiver = new ACDeviceDataMgr.PropertyReceiver() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass1 */

            @Override // com.accloud.service.ACDeviceDataMgr.PropertyReceiver
            public void onPropertyReceive(String s, long l, String s1) {
                PropertyInfo info;
                boolean z;
                boolean z2 = false;
                if (!MapActivity_786.this.isStoped && (info = (PropertyInfo) new Gson().fromJson(s1, PropertyInfo.class)) != null) {
                    MapActivity_786.this.clearAll();
                    int errorCode = info.getError_info();
                    if (errorCode != 0) {
                        MapActivity_786.this.isError = true;
                        if (MapActivity_786.this.popWnd_error != null && !MapActivity_786.this.popWnd_error.isShowing()) {
                            MapActivity_786.this.showErrorPopup(errorCode);
                        }
                    } else if (MapActivity_786.this.popWnd_error != null && MapActivity_786.this.popWnd_error.isShowing()) {
                        MapActivity_786.this.popWnd_error.dismiss();
                    }
                    int workPattern = info.getWork_pattern();
                    MyLog.e(MapActivity_786.this.TAG, "initPropertyReceiver  onPropertyReceive workPattern = " + workPattern);
                    switch (workPattern) {
                        case 0:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_offline));
                            break;
                        case 1:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_sleep_));
                            break;
                        case 2:
                            MapActivity_786.this.isStandBy = true;
                            if (!MapActivity_786.this.isError) {
                                MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_standby_mode));
                                break;
                            } else {
                                MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_device_error));
                                break;
                            }
                        case 3:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_random));
                            MapActivity_786.this.isStart = true;
                            MapActivity_786.this.isRandom = true;
                            break;
                        case 4:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_alongwall));
                            MapActivity_786.this.isAlongWall = true;
                            MapActivity_786.this.isStart = true;
                            break;
                        case 5:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_keyPoint_mode));
                            MapActivity_786.this.isKeyPoint = true;
                            break;
                        case 6:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_plan_mode));
                            MapActivity_786.this.isStart = true;
                            break;
                        case 8:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_recharge_mode));
                            MapActivity_786.this.isRecharge = true;
                            break;
                        case 9:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_charge));
                            MapActivity_786.this.isCharging = true;
                            break;
                        case 10:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_remotecontrol));
                            MapActivity_786.this.isRemote = true;
                            break;
                        case 11:
                            MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_find_));
                            break;
                    }
                    int cleanForce = info.getVacuum_cleaning();
                    MapActivity_786.this.batteryCap = info.getBattery_level();
                    MapActivity_786 mapActivity_786 = MapActivity_786.this;
                    if (cleanForce > 0) {
                        z = true;
                    } else {
                        z = false;
                    }
                    mapActivity_786.isMaxMode = z;
                    if (!MapActivity_786.this.isCharging) {
                        MapActivity_786.this.setBatteryImage(MapActivity_786.this.batteryCap);
                    } else if (MapActivity_786.this.batteryCap >= 98) {
                        MapActivity_786.this.image_battery.setImageResource(R.drawable.map_aty_charge_full);
                    } else {
                        MapActivity_786.this.image_battery.setImageResource(R.drawable.map_aty_charging);
                    }
                    MapActivity_786.this.initStates();
                    if (MapActivity_786.this.popWnd_control != null && !MapActivity_786.this.popWnd_control.isShowing()) {
                        MapActivity_786 mapActivity_7862 = MapActivity_786.this;
                        if (MapActivity_786.this.isStandBy || MapActivity_786.this.isRemote) {
                            z2 = true;
                        }
                        mapActivity_7862.setControlStatus(z2);
                    }
                    MapActivity_786.this.hidePopControl();
                }
            }
        };
    }

    private void registerPropertyReceiver() {
        AC.deviceDataMgr().subscribeProperty(this.subdomain, this.deviceId, new VoidCallback() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass2 */

            @Override // com.accloud.cloudservice.VoidCallback
            public void success() {
                AC.deviceDataMgr().registerPropertyReceiver(MapActivity_786.this.myPropertyReceiver);
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    private void getWorkStatus() {
        sendToDevice_WorkStatus(new ACDeviceMsg(65, new byte[]{0}), this.physicalDeviceId);
    }

    public void getClockInfo() {
        sendToDevice_ClockInfo(new ACDeviceMsg(66, new byte[]{0}), this.physicalDeviceId);
    }

    private void getDeviceInfo() {
        this.context = this;
        this.physicalDeviceId = SpUtils.getSpString(this.context, "physicalDeviceId");
        this.subdomain = SpUtils.getSpString(this.context, "subdomain");
        this.deviceId = SpUtils.getLong(this.context, "deviceId");
        this.msg_workMode = new ACDeviceMsg();
        LogUtil.d("getDeviceInfo-->"+msg_workMode.toString());
        this.msg_workMode.setCode(70);
    }

    public void initReceiver() {
        this.receiver = new MyReceiver();
        this.filter = new IntentFilter();
        this.filter.addAction("com.example.MapActivity");
    }

    private void initView() {
        initTitle();
        this.popWnd_error = new PopupWindow(this.context);
        this.line_state = (LinearLayout) findViewById(R.id.line_state);
        this.line_state.setVisibility(8);
        this.relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        this.image_gif = (ImageView) findViewById(R.id.image_gif);
        Glide.with((FragmentActivity) this).load(Integer.valueOf((int) R.drawable.map_bg)).into(this.image_gif);
        this.image_back = (ImageView) findViewById(R.id.image_back);
        this.image_setting = (ImageView) findViewById(R.id.image_setting);
        this.image_start = (ImageView) findViewById(R.id.image_start);
        this.image_recharge = (ImageView) findViewById(R.id.image_recharge);
        this.image_keyPoint = (ImageView) findViewById(R.id.image_key_point);
        this.anchorView = findViewById(R.id.view_);
        this.tv_state = (TextView) findViewById(R.id.tv_state);
        this.tv_area = (TextView) findViewById(R.id.tv_area);
        this.tv_time = (TextView) findViewById(R.id.tv_time);
        this.tv_start = (TextView) findViewById(R.id.tv_start);
        this.tv_recharge = (TextView) findViewById(R.id.tv_recharge);
        this.tv_keyPoint = (TextView) findViewById(R.id.tv_keyPoint);
        this.tab_start = (RelativeLayout) findViewById(R.id.tab_start);
        this.tab_recharge = (RelativeLayout) findViewById(R.id.tab_recharge);
        this.tab_keyPoint = (RelativeLayout) findViewById(R.id.tab_keyPoint);
        this.popWnd_control = new PopupWindowWithMask(this.context, this.relativeLayout, this.physicalDeviceId, this.subdomain);
        this.popWnd_control.setOnDismissListener(new PopupWindow.OnDismissListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass3 */

            @Override // android.widget.PopupWindow.OnDismissListener
            public void onDismiss() {
                MapActivity_786.this.setControlStatus(MapActivity_786.this.isStandBy || MapActivity_786.this.isRemote);
            }
        });
        initZoom();
    }

    private void initTitle() {
        ((TextView) findViewById(R.id.tv_title)).setText(getString(R.string.map_aty_title, new Object[]{"X786"}));
    }

    public void initZoom() {
        this.image_battery = DisplayUtil.initRightZoom(this.context, this.relativeLayout, R.id.image_battery);
        this.image_battery.setImageResource(R.drawable.map_aty_battery4);
        this.image_clock = DisplayUtil.initRightZoom(this.context, this.relativeLayout, R.id.image_clock);
        this.image_clock.setImageResource(R.drawable.map_aty_clock_gray_);
        this.image_control = DisplayUtil.initLeftZoom(this.context, this.relativeLayout, 2131755021, R.drawable.remote_gray);
        setControlStatus(false);
    }

    private void setListener() {
        this.image_back.setOnClickListener(this);
        this.image_setting.setOnClickListener(this);
        this.tab_start.setOnClickListener(this);
        this.tab_recharge.setOnClickListener(this);
        this.tab_keyPoint.setOnClickListener(this);
        this.image_control.setOnClickListener(this);
        this.image_clock.setOnClickListener(this);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_clock /* 2131755020 */:
//                this.intent_clock = new Intent(this, ClockingActivity_780_.class);
//                startActivity(this.intent_clock);
                return;
            case 2131755021 /* 2131755021 */:
                if (this.popWnd_control != null) {
                    setControlStatus(false);
                    this.popWnd_control.showAtLocation(this.relativeLayout, 17, 0, 0);
                    return;
                }
                return;
            case R.id.image_back /* 2131755189 */:
                finish();
                return;
            case R.id.image_setting /* 2131755294 */:
//                startActivity(new Intent(this.context, SettingActivity_786.class));
                return;
            case R.id.tab_recharge /* 2131755310 */:
                if (this.isCharging) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_charging));
                    return;
                } else {
                    clickTab(R.id.tab_recharge);
                    return;
                }
            case R.id.tab_start /* 2131755313 */:
                clickTab(R.id.tab_start);
                return;
            case R.id.tab_keyPoint /* 2131755316 */:
                if (this.isRecharge && this.subdomain.equals(Constants.subdomain_x786)) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_can_not_execute));
                    return;
                } else if (this.isCharging) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_charging));
                    return;
                } else {
                    clickTab(R.id.tab_keyPoint);
                    return;
                }
            case R.id.image_delete /* 2131755614 */:
            case R.id.rl_error /* 2131755731 */:
            default:
                return;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showErrorPopup(int errorCode) {
        View contentView = LayoutInflater.from(this.context).inflate(R.layout.popup_error, (ViewGroup) null);
        initErrorPopup(errorCode, contentView);
        this.popWnd_error.setBackgroundDrawable(new ColorDrawable(0));
        this.popWnd_error.setContentView(contentView);
        this.popWnd_error.setOutsideTouchable(false);
        this.popWnd_error.setFocusable(false);
        this.popWnd_error.setWidth(-1);
        this.popWnd_error.setHeight(-2);
        this.popWnd_error.showAsDropDown(this.anchorView);
    }

    public void initErrorPopup(int errorCode, View contentView) {
        DeviceUtils.setErroeText(this.context, errorCode, (TextView) contentView.findViewById(R.id.tv_error));
        ((ImageView) contentView.findViewById(R.id.image_delete)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass4 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                if (MapActivity_786.this.popWnd_error != null) {
                    MapActivity_786.this.popWnd_error.dismiss();
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clearAll() {
        this.image_start.setSelected(false);
        this.image_recharge.setSelected(false);
        this.image_keyPoint.setSelected(false);
        this.tv_start.setSelected(false);
        this.tv_recharge.setSelected(false);
        this.tv_keyPoint.setSelected(false);
        this.isRecharge = false;
        this.isStart = false;
        this.isKeyPoint = false;
        this.isStandBy = false;
        this.isCharging = false;
        this.isRandom = false;
        this.isRemote = false;
        this.isMaxMode = false;
        this.isError = false;
        this.isAlongWall = false;
    }

    private void clickTab(int resId) {
        switch (resId) {
            case R.id.tab_recharge /* 2131755310 */:
                if (!this.isRecharge) {
                    this.msg_workMode.setContent(new byte[]{8});
                } else {
                    this.msg_workMode.setContent(new byte[]{2});
                }
                sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                break;
            case R.id.tab_start /* 2131755313 */:
                if (!this.isStart) {
                    if (this.batteryCap > 0 && this.batteryCap <= 6) {
                        ToastUtils.showToast(this.context, getString(R.string.low_battery));
                    }
                    int workMode = SpUtils.getInt(this.context, this.physicalDeviceId + "workMode");
                    if (workMode == 100) {
                        if (DeviceUtils.is430Or780or800or900(this.subdomain)) {
                            this.msg_workMode.setContent(new byte[]{6});
                        } else if (DeviceUtils.is782oR785(this.subdomain)) {
                            this.msg_workMode.setContent(new byte[]{3});
                        }
                    } else if (workMode == 6) {
                        this.msg_workMode.setContent(new byte[]{6});
                    } else if (workMode == 3) {
                        this.msg_workMode.setContent(new byte[]{3});
                    }
                } else {
                    this.msg_workMode.setContent(new byte[]{2});
                }
                sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                break;
            case R.id.tab_keyPoint /* 2131755316 */:
                if (!this.isKeyPoint) {
                    this.msg_workMode.setContent(new byte[]{5});
                } else {
                    this.msg_workMode.setContent(new byte[]{2});
                }
                sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                break;
        }
        this.isClickTab = true;
        setAllUnClickable();
    }

    public void setBatteryImage(int batteryCap2) {
        DisplayUtil.setBatteryImage(batteryCap2, this.image_battery);
    }

    public void sendToDevice_WorkStatus(ACDeviceMsg deviceMsg, final String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass5 */

            public void success(ACDeviceMsg deviceMsg) {
                boolean z;
                boolean z2 = false;
                if (!MapActivity_786.this.isStoped) {
                    switch (deviceMsg.getCode()) {
                        case 65:
                            byte[] byte_decStatus = deviceMsg.getContent();
                            if (byte_decStatus != null && byte_decStatus.length == 9) {
                                MapActivity_786.this.clearAll();
                                int error = byte_decStatus[8] & Draft_75.END_OF_FRAME;
                                if (error != 0) {
                                    MapActivity_786.this.isError = true;
                                    if (MapActivity_786.this.popWnd_error != null && !MapActivity_786.this.popWnd_error.isShowing()) {
                                        MapActivity_786.this.showErrorPopup(error);
                                    }
                                } else if (MapActivity_786.this.popWnd_error != null && MapActivity_786.this.popWnd_error.isShowing()) {
                                    MapActivity_786.this.popWnd_error.dismiss();
                                }
                                byte workStatus_ = byte_decStatus[0];
                                if (workStatus_ == 0) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_offline));
                                } else if (workStatus_ == 1) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_sleep));
                                } else if (workStatus_ == 2) {
                                    if (MapActivity_786.this.isError) {
                                        MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_device_error));
                                    } else {
                                        MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_standby_mode));
                                    }
                                    MapActivity_786.this.isStandBy = true;
                                } else if (workStatus_ == 3) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_random));
                                    MapActivity_786.this.isStart = true;
                                    MapActivity_786.this.isRandom = true;
                                } else if (workStatus_ == 4) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_alongwall));
                                    MapActivity_786.this.isAlongWall = true;
                                    MapActivity_786.this.isStart = true;
                                } else if (workStatus_ == 5) {
                                    MapActivity_786.this.isKeyPoint = true;
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_keyPoint_mode));
                                } else if (workStatus_ == 6) {
                                    MapActivity_786.this.isStart = true;
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_plan_mode));
                                } else if (workStatus_ == 8) {
                                    MapActivity_786.this.isRecharge = true;
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_recharge_mode));
                                } else if (workStatus_ == 9) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_charge));
                                    MapActivity_786.this.isCharging = true;
                                } else if (workStatus_ == 10) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_remote));
                                    MapActivity_786.this.isRemote = true;
                                } else if (workStatus_ == 11) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_find));
                                }
                                SpUtils.saveInt(MapActivity_786.this.context, physicalDeviceId2 + "mopForce", byte_decStatus[4]);
                                MapActivity_786 mapActivity_786 = MapActivity_786.this;
                                if (byte_decStatus[3] > 0) {
                                    z = true;
                                } else {
                                    z = false;
                                }
                                mapActivity_786.isMaxMode = z;
                                MapActivity_786.this.batteryCap = byte_decStatus[5];
                                if (!MapActivity_786.this.isCharging) {
                                    MapActivity_786.this.setBatteryImage(MapActivity_786.this.batteryCap);
                                } else if (MapActivity_786.this.batteryCap >= 98) {
                                    MapActivity_786.this.image_battery.setImageResource(R.drawable.map_aty_charge_full);
                                } else {
                                    MapActivity_786.this.image_battery.setImageResource(R.drawable.map_aty_charging);
                                }
                                SpUtils.saveInt(MapActivity_786.this.context, physicalDeviceId2 + "batteryCap", MapActivity_786.this.batteryCap);
                                break;
                            } else {
                                return;
                            }
                        case 70:
                            byte[] resp_wokeMode = deviceMsg.getContent();
                            if (resp_wokeMode != null && resp_wokeMode.length == 1) {
                                MapActivity_786.this.clearAll();
                                byte workStatus = resp_wokeMode[0];
                                MyLog.e(MapActivity_786.this.TAG, "sendToDevice_WorkStatus success workStatus = " + ((int) workStatus));
                                if (workStatus == 6) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_plan_mode));
                                    MapActivity_786.this.isStart = true;
                                } else if (workStatus == 5) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_keyPoint_mode));
                                    MapActivity_786.this.isKeyPoint = true;
                                } else if (workStatus == 8) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_recharge_mode));
                                    MapActivity_786.this.isRecharge = true;
                                } else if (workStatus == 2) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_standby_mode));
                                    MapActivity_786.this.isStandBy = true;
                                } else if (workStatus == 3) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_random));
                                    MapActivity_786.this.isStart = true;
                                    MapActivity_786.this.isRandom = true;
                                } else if (workStatus == 9) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_charge));
                                    MapActivity_786.this.isCharging = true;
                                    ToastUtils.showToast(MapActivity_786.this.context, MapActivity_786.this.getString(R.string.map_aty_charging));
                                } else if (workStatus == 10) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_remote));
                                    MapActivity_786.this.isRemote = true;
                                } else if (workStatus == 4) {
                                    MapActivity_786.this.tv_state.setText(MapActivity_786.this.getString(R.string.map_aty_alongwall));
                                    MapActivity_786.this.isAlongWall = true;
                                    MapActivity_786.this.isStart = true;
                                }
                                MapActivity_786.this.setAllClickable();
                                break;
                            } else {
                                return;
                            }
//                            break;
                    }
                    MapActivity_786.this.initStates();
                    MapActivity_786 mapActivity_7862 = MapActivity_786.this;
                    if (MapActivity_786.this.isStandBy || MapActivity_786.this.isRemote) {
                        z2 = true;
                    }
                    mapActivity_7862.setControlStatus(z2);
                } else if (MapActivity_786.this.isClickTab) {
                    MapActivity_786.this.isClickTab = false;
                    MapActivity_786.this.setAllClickable();
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                ToastUtils.showErrorToast(MapActivity_786.this.context, e.getErrorCode());
                if (MapActivity_786.this.isClickTab) {
                    MapActivity_786.this.isClickTab = false;
                    MapActivity_786.this.setAllClickable();
                }
            }
        });
    }

    public void sendToDevice_ClockInfo(ACDeviceMsg deviceMsg, final String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass6 */

            public void success(ACDeviceMsg acDeviceMsg) {
                if (!MapActivity_786.this.isStoped) {
                    byte[] resp = acDeviceMsg.getContent();
                    if (resp != null && resp.length == 50) {
                        for (int i = 0; i < resp.length; i++) {
                            if (i % 5 == 0 && resp[i + 1] != 0) {
                                if (MapActivity_786.this.image_battery.getVisibility() == 0) {
                                    MapActivity_786.this.image_clock.setImageResource(R.drawable.map_aty_clock_);
                                    MapActivity_786.this.image_clock.setVisibility(0);
                                }
                                MapActivity_786.this.sendToDevice_CurTime(new ACDeviceMsg(76, TimeUtil.getTimeBytes()), physicalDeviceId2);
                                return;
                            }
                        }
                    }
                    if (MapActivity_786.this.image_battery.getVisibility() == 0) {
                        MapActivity_786.this.image_clock.setImageResource(R.drawable.map_aty_clock_gray_);
                        MapActivity_786.this.image_clock.setVisibility(0);
                    }
                    MapActivity_786.this.sendToDevice_CurTime(new ACDeviceMsg(76, TimeUtil.getTimeBytes()), physicalDeviceId2);
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                if (MapActivity_786.this.image_battery.getVisibility() == 0) {
                    MapActivity_786.this.image_clock.setImageResource(R.drawable.map_aty_clock_gray_);
                    MapActivity_786.this.image_clock.setVisibility(0);
                }
            }
        });
    }

    public void sendToDevice_CurTime(ACDeviceMsg deviceMsg, String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_786.AnonymousClass7 */

            public void success(ACDeviceMsg acDeviceMsg) {
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    public void initStates() {
        this.tv_start.setText(this.isStart ? getString(R.string.map_aty_stop_clean) : getString(R.string.map_aty_start_clean));
        this.image_start.setSelected(this.isStart);
        this.tv_start.setSelected(this.isStart);
        this.image_recharge.setSelected(this.isRecharge);
        this.tv_recharge.setSelected(this.isRecharge);
        this.image_keyPoint.setSelected(this.isKeyPoint);
        this.tv_keyPoint.setSelected(this.isKeyPoint);
        this.tv_area.setText("——");
        this.tv_time.setText("——");
    }

    public void setControlStatus(boolean isClickable) {
        this.image_control.setImageResource(isClickable ? R.drawable.map_aty_dir_clickable_ : R.drawable.map_aty_dir_unclickable_);
        this.image_control.setClickable(isClickable);
    }

    public class MyReceiver extends BroadcastReceiver {
        int cleanArea;
        int workTime;

        public MyReceiver() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if (MapActivity_786.this.isStart && !MapActivity_786.this.isRandom) {
                this.workTime = intent.getIntExtra("workTime", 0);
                this.cleanArea = intent.getIntExtra("cleanArea", 0);
                MapActivity_786.this.tv_area.setText((((double) this.cleanArea) / 100.0d) + "㎡");
                MapActivity_786.this.tv_time.setText((this.workTime / 60) + "min");
            }
        }
    }

    public void setAllClickable() {
        this.tab_start.setClickable(true);
        this.tab_keyPoint.setClickable(true);
        this.tab_recharge.setClickable(true);
    }

    public void setAllUnClickable() {
        this.tab_start.setClickable(false);
        this.tab_keyPoint.setClickable(false);
        this.tab_recharge.setClickable(false);
    }

    public void hidePopControl() {
        if ((this.isStart || this.isKeyPoint || this.isRecharge) && this.popWnd_control != null && this.popWnd_control.isShowing()) {
            this.popWnd_control.dismiss();
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onStop() {
        super.onStop();
        this.isStoped = true;
        if (this.registerTag) {
            this.registerTag = false;
            unregisterReceiver(this.receiver);
        }
        if (this.popWnd_error != null && this.popWnd_error.isShowing()) {
            this.popWnd_error.dismiss();
        }
        if (this.myPropertyReceiver != null) {
            this.myPropertyReceiver = null;
        }
    }

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onBackPressed() {
        if (this.popWnd_error == null || !this.popWnd_error.isShowing()) {
            super.onBackPressed();
        } else {
            this.popWnd_error.dismiss();
        }
    }
}
